package practice;

import javax.inject.Named;

import practice.APIResponse.Status;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;

@Api(name = "email")
public class GAEEmailApi {

	@ApiMethod(path = "sendDummyEmailWithCSVAttachment", httpMethod = HttpMethod.POST)
	public APIResponse sendDummyEmailWithCSVAttachment(@Named("validToAddress") String toEmail) {
		try {

			EmailProp emailProp = new EmailProp();
			emailProp.attachmentName = "test.csv";
			emailProp.bodyHtml = "<h3>Sample html content </h3>";
			emailProp.subject = "Test subject";
			emailProp.fromEmailAddress = "sathya.t@ishafoundation.org";
			emailProp.toEmailAddress = toEmail;
			emailProp.sendCSVAttachment = true;
			emailProp.csvAttachmentData = "first name, last name\nsathya,thilakan\nsowmya,ramakrishnan\nrithvik,sathyanarayanan";

			GAEEmail.send(emailProp);

			return new APIResponse(Status.SUCCESS, "Sent dummy email from "
					+ emailProp.fromEmailAddress + " to "
					+ emailProp.toEmailAddress);

		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}
}
